package java8.date;

import org.junit.Test;

import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.time.format.FormatStyle;

public class FormattingTest {

    @Test
    public void demo(){
        DateTimeFormatter formatter1 = DateTimeFormatter.ofLocalizedDateTime(FormatStyle.MEDIUM);
        LocalDateTime example = LocalDateTime.of(2000, 3, 19, 10, 56, 59);
        System.out.println("Format 1: " + example.format(formatter1));

        DateTimeFormatter formatter2 = DateTimeFormatter.ofPattern("MMMM dd, yyyy HH:mm:ss");
        System.out.println("Format 2: " + example.format(formatter2));

        DateTimeFormatter formatter3 = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
        System.out.println("Format 3: " + example.format(formatter3));

        LocalDateTime parse = LocalDateTime.parse("2000-03-19 10:56:59", formatter3);
        //获取一年中的第几天
        System.out.println("date year: " + parse.getDayOfYear());
    }
}
